//package com.sdkj.dspservice.modules.report.api;
//
//import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
//import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
//import com.sdkj.dspservice.common.base.controller.BaseController;
//import com.sdkj.dspservice.common.react.AntdProResult;
//import com.sdkj.dspservice.modules.report.entity.View;
//import com.sdkj.dspservice.modules.report.entity.tem.PaginateWithQueryColumns;
//import com.sdkj.dspservice.modules.report.service.ViewService;
//import com.sdkj.dspservice.modules.report.utils.DacChannelUtil;
//import io.swagger.annotations.Api;
//import io.swagger.annotations.ApiOperation;
//import io.swagger.annotations.ApiResponse;
//import io.swagger.annotations.ApiResponses;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.http.MediaType;
//import org.springframework.web.bind.annotation.*;
//
//import javax.validation.Valid;
//import java.rmi.ServerException;
//
///**
// * 数据视图控制器
// * @author tm
// */
//@Api(value = "数据视图", tags = "数据视图控制器")
//@ApiResponses(@ApiResponse(code = 404, message = "数据视图不存在"))
//@Slf4j
//@RestController
//@RequestMapping(value = "${project-config.apiUrl}/${project-config.version}/report/view")
//public class ViewController extends BaseController {
//
//    @Autowired
//    private ViewService viewService;
//
//    @Autowired
//    private DacChannelUtil dacChannelUtil;
//
//    /**
//     * 获取详情
//     *
//     * @param id
//     * @return
//     */
//    @ApiOperation(value = "获取详情")
//    @GetMapping(value = "get")
//    public AntdProResult get(String id) {
//        AntdProResult result = new AntdProResult();
//        View view = viewService.getById(id);
//        result.success(view);
//        return result;
//    }
//
//    /**
//     * 获取列表
//     *
//     * @param view
//     * @return
//     */
//    @ApiOperation(value = "获取列表")
//    @GetMapping(value = "list")
//    public AntdProResult list(View view) {
//        AntdProResult result = new AntdProResult();
//        Page<View> viewsPage = viewService.page(new Page<>(view.current, view.pageSize), new QueryWrapper<>(view));
//        result.success(viewsPage);
//        return result;
//    }
//
//    /**
//     * 保存（添加或修改）
//     *
//     * @param view
//     * @return
//     */
//    @ApiOperation(value = "保存（添加或修改）")
//    @PostMapping(value = "save")
//    public AntdProResult save(@Valid @RequestBody View view) {
//        AntdProResult result = new AntdProResult();
//        viewService.saveOrUpdate(view);
//        return result;
//    }
//
//    /**
//     * 删除
//     *
//     * @param id
//     * @return
//     */
//    @ApiOperation(value = "删除")
//    @RequestMapping(value = "remove")
//    public AntdProResult delete(String id) {
//        AntdProResult result = new AntdProResult();
//        viewService.removeById(id);
//        return result;
//    }
//
//
//    /**
//     * 执行sql
//     *
//     * @param executeSql
//     * @return
//     */
//    @ApiOperation(value = "executeSql")
//    @PostMapping(value = "/executeSql", consumes = MediaType.APPLICATION_JSON_VALUE)
//    public AntdProResult executeSql(@Valid @RequestBody View view) {
//        AntdProResult result = new AntdProResult();
//        PaginateWithQueryColumns paginateWithQueryColumns = null;
//        try {
//            paginateWithQueryColumns = viewService.executeSql(view);
//            result.success(paginateWithQueryColumns);
//        } catch (ServerException e) {
//            e.printStackTrace();
//            result.error(AntdProResult.SYSTEM_ERROR, "系统错误");
//        }
//        return result;
//    }
//
//
////    /**
////     * 获取当前view对应的源数据
////     *
////     * @param id
////     * @param executeParam
////     * @param user
////     * @param request
////     * @return
////     */
////    @ApiOperation(value = "get data")
////    @PostMapping(value = "/{id}/getdata", consumes = MediaType.APPLICATION_JSON_VALUE)
////    public ResponseEntity getData(@PathVariable Long id,
////                                  @RequestBody(required = false) ViewExecuteParam executeParam,
////                                  @ApiIgnore @CurrentUser User user,
////                                  HttpServletRequest request) throws SQLException {
////        if (invalidId(id)) {
////            ResultMap resultMap = new ResultMap(tokenUtils).failAndRefreshToken(request).message("Invalid view id");
////            return ResponseEntity.status(resultMap.getCode()).body(resultMap);
////        }
////
////        Paginate<Map<String, Object>> paginate = viewService.getData(id, executeParam, user);
////        return ResponseEntity.ok().cacheControl(CacheControl.noCache()).body(new ResultMap(tokenUtils).successAndRefreshToken(request).payload(paginate));
////    }
////
////
////    @ApiOperation(value = "get distinct value")
////    @PostMapping(value = "/{id}/getdistinctvalue", consumes = MediaType.APPLICATION_JSON_VALUE)
////    public ResponseEntity getDistinctValue(@PathVariable Long id,
////                                           @Valid @RequestBody DistinctParam param,
////                                           @ApiIgnore BindingResult bindingResult,
////                                           @ApiIgnore @CurrentUser User user,
////                                           HttpServletRequest request) {
////        if (invalidId(id)) {
////            ResultMap resultMap = new ResultMap(tokenUtils).failAndRefreshToken(request).message("Invalid view id");
////            return ResponseEntity.status(resultMap.getCode()).body(resultMap);
////        }
////
////        if (bindingResult.hasErrors()) {
////            ResultMap resultMap = new ResultMap(tokenUtils).failAndRefreshToken(request).message(bindingResult.getFieldErrors().getById(0).getDefaultMessage());
////            return ResponseEntity.status(resultMap.getCode()).body(resultMap);
////        }
////
////        List<Map<String, Object>> distinctValue = viewService.getDistinctValue(id, param, user);
////        return ResponseEntity.ok(new ResultMap(tokenUtils).successAndRefreshToken(request).payloads(distinctValue));
////    }
////
////
////    @ApiOperation(value = "get dac channels")
////    @GetMapping("/dac/channels")
////    public ResponseEntity getDacChannels(@ApiIgnore @CurrentUser User user, HttpServletRequest request) {
////        Map<String, DacChannel> dacMap = DacChannelUtil.dacMap;
////        return ResponseEntity.ok(new ResultMap(tokenUtils).successAndRefreshToken(request).payloads(dacMap.keySet()));
////    }
////
////    @ApiOperation(value = "get dac tenants")
////    @GetMapping("/dac/{dacName}/tenants")
////    public ResponseEntity getDacTannets(@PathVariable String dacName, @ApiIgnore @CurrentUser User user, HttpServletRequest request) {
////
////        return ResponseEntity.ok(new ResultMap(tokenUtils).successAndRefreshToken(request).payloads(dacChannelUtil.getTenants(dacName)));
////    }
////
////
////    @ApiOperation(value = "get dac bizs")
////    @GetMapping("/dac/{dacName}/tenants/{tenantId}/bizs")
////    public ResponseEntity getDacBizs(@PathVariable String dacName,
////                                     @PathVariable String tenantId,
////                                     @ApiIgnore @CurrentUser User user,
////                                     HttpServletRequest request) {
////        return ResponseEntity.ok(new ResultMap(tokenUtils).successAndRefreshToken(request).payloads(dacChannelUtil.getBizs(dacName, tenantId)));
////    }
//}
